
import InputStream from "../../stream";
import {ResponseOperate} from "../../opearte";

export function  loginPacketResp(stream:InputStream){


    const register=stream.readByte();

     const status=stream.readByte();
     const isAdult=stream.readByte();
     const token=stream.readString();
     return {
         register:register===1,
         status: status === 1,
         isAdult: isAdult===1,
         token

     }




}

export function regionPacketResp(stream:InputStream){
    let zoneCount=stream.readInt();
    const zones=new Array<any>();
    console.info(zoneCount)
    for (let i=0;i<zoneCount;i++){
        const zoneId=stream.readByte();


        const  zoneName=stream.readString();
        console.info(zoneName)
        const  serverCount=stream.readInt();
        console.info(serverCount);
        const  servers=new Array<any>();
        for (let j=0;j<serverCount;j++){

            const id=stream.readShort();
            const name=stream.readString();
            const serverIp=stream.readString();

            const delay=stream.readShort();
            const status=stream.readByte();
            const type = stream.readByte();
            servers[j]={id,name,serverIp,delay,status,type};
            console.info(id,name,serverIp,delay,status,type)

        }
        zones[i]={zoneId,zoneName,servers}
    }

    return {type:ResponseOperate.LOAD_REGION,data:zones}

}

export function  channelPacketResp(stream:InputStream){

    const channelCount=stream.readInt();
    const channels=new Array<any>();
    for (let i=0;i<channelCount;i++){
        const id=stream.readShort();
        const name=stream.readString();
        const serverIp=stream.readString();
        const port =stream.readShort();
        const status=stream.readByte();
        const delay=stream.readShort();

        const maxOnline=stream.readShort();
        const online=stream.readShort();
        channels[i]= {
            id,name,serverIp,port,status,maxOnline,online,delay
        }



    }
    return {type:ResponseOperate.LOAD_CHANNEL,data:channels}
}